
var Api = require('../../utils/api.js');
var util = require('../../utils/util.js');
var Auth = require('../../utils/auth.js');

var wxApi = require('../../utils/wxApi.js')
var wxRequest = require('../../utils/wxRequest.js');
var app = getApp();
var webSiteName= config.getWebsiteName;
var domain =config.getDomain
import config from '../../utils/config.js'
Page({
  data: {
    is_showWarranty:false,
    title: '质保查询',
    page: 1,
    search: '', 
    showerror:"none", 
    showallDisplay: "block",
    displaySwiper: "block",
    floatDisplay: "none", 
    webSiteName:webSiteName,
    domain:domain,
    windowHeight:'100%',
    windowWidth:'100%',
    inFinChat:false, 
    userInfo: {},
    isLoginPopup:false,
    openid: '',
  },
  verifyLogin:function(e){
    if(!this.data.userInfo.isLogin){
      this.setData({
        isLoginPopup: false
      });
      return false;
    }
  },
  myWarranty:function(e){
     
    if(!this.data.userInfo.isLogin){
      this.setData({
        isLoginPopup: true
      });
      return false;
    }
    wx.navigateTo({
      url: '../warrantyManageList/manageList'
    })
  },
  searchWarranty:function(e){
    if(!this.data.userInfo.isLogin){
      this.setData({
        isLoginPopup: true
      });
      return false;
    }
    wx.navigateTo({
      url: '/pages/warrantyCheck/check'
    })
  },
  showWarranty:function(e){
    this.setData({
        is_showWarranty: true
    });
 
  },
  actWarranty:function(e){
    
    if(!this.data.userInfo.isLogin){
      this.setData({
        isLoginPopup: true
      });
      return false;
    }
    wx.navigateTo({
      url: '../warrantyAdd/add'
    })
  },
  actWindowsWarranty:function(e){
    if(!this.data.userInfo.isLogin){
      this.setData({
        isLoginPopup: true
      });
      return false;
    }
    wx.navigateTo({
      url: '../warrantyWindowAdd/add'
    })
  },
  onLoad: function (options) {
    //需要用户登录
    var self = this;
    wx.getSystemInfo({ 
      success: (result) => {
        self.setData({
          windowHeight:result.windowHeight,
          windowWidth:result.windowWidth
        }) 
        if(result.inFinChat)
        {          
          self.setData({inFinChat:result.inFinChat})          
        }
        else{          
          Auth.setUserInfoData(self);
          Auth.checkLogin(self);
          Auth.checkSession(self, 'isLoginNow');
        }
      },
    })
    console.log(self.data);
  },
  onShow() {
    var self = this;
    wx.getSystemInfo({ 
      success: (result) => {
        if(result.inFinChat)
        {          
          self.setData({inFinChat:result.inFinChat})          
        }
        else{          
          Auth.setUserInfoData(self);
          Auth.checkLogin(self);
          self.setData({copyright: getApp().globalData.copyright})
          Auth.checkSession(self, 'isLoginNow');
        }
      },
    })
  },
  agreeGetUser: function(e) {
    let self = this;
    Auth.checkAgreeGetUser(e, app, self, '0');
  },
  getPhoneNumber (e) {
    Auth.getUserMobile(e, e.detail.code);
    console.log(e.detail.code);
  },

  closeLoginPopup() {
    this.setData({
      isLoginPopup: false
    });
  },
  openLoginPopup() {
    this.setData({
      isLoginPopup: true
    });
  },
})



